package com.market.manage.controller;

import com.market.manage.service.UploadLoadService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.FileNotFoundException;

@CrossOrigin
@RestController
@RequestMapping(value = "/upload")
public class UploadController {
    @Resource
    private UploadLoadService uploadLoadServiceImpl;

    /**
     * 处理文件上传的接口
     *
     * @param file
     * @return
     * @throws FileNotFoundException
     */
    @PostMapping("/file")
    public String upload(MultipartFile file) throws FileNotFoundException {
        return uploadLoadServiceImpl.upload(file);
    }

    /**
     * 发表文件接口
     */
    @PostMapping("/article")
    public void article(String title, String article, Long[] ids) {
        uploadLoadServiceImpl.publicArticle(title, article, ids);
    }

}
